<template>
		<div class="apply_box">
			
			<h3 class="apply_title">
				您要申请:<span>{{productName}}</span>
			</h3>
			<!-- 申请表单 -->
			<Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
		        <FormItem label="姓名" prop="name">
		            <Input v-model="formValidate.name" placeholder="请输入姓名"></Input>
		        </FormItem>
		        <FormItem label="身份证号" prop="idNum">
		            <Input v-model="formValidate.idNum" placeholder="请输入身份证号"></Input>
		        </FormItem>
		        <FormItem label="手机号" prop="phoneNum">
		            <Input v-model="formValidate.phoneNum" placeholder="请输入手机号"></Input>
		        </FormItem>
		        <FormItem label="E-mail" prop="mail">
		            <Input v-model="formValidate.mail" placeholder="请输邮箱"></Input>
		        </FormItem>
		        <FormItem label="住址" prop="city">
		            <Select v-model="formValidate.city" placeholder="选择您的住址">
		                <Option value="beijing">北京</Option>
		                <Option value="shanghai">上海</Option>
		                <Option value="shenzhen">深圳</Option>
		            </Select>
		        </FormItem>
		        <FormItem prop="date" label="出生日期">
		             <DatePicker type="date" placeholder="选择出生日期" v-model="formValidate.date"></DatePicker>
		        </FormItem>
		        <!-- <FormItem label="出生日期">
		            <Row>
		                <Col span="11">
		                    <FormItem prop="date">
		                        <DatePicker type="date" placeholder="选择出生日期" v-model="formValidate.date"></DatePicker>
		                    </FormItem>
		                </Col>
		                <Col span="2" style="text-align: center">-</Col>
		                <Col span="11">
		                    <FormItem prop="time">
		                        <TimePicker type="time" placeholder="Select time" v-model="formValidate.time"></TimePicker>
		                    </FormItem>
		                </Col>
		            </Row>
		        </FormItem> -->
		        <FormItem label="性别" prop="gender">
		            <RadioGroup v-model="formValidate.gender">
		                <Radio label="男">男</Radio>
		                <Radio label="女">女</Radio>
		            </RadioGroup>
		        </FormItem>
		        <FormItem label="爱好" prop="interest">
		            <CheckboxGroup v-model="formValidate.interest">
		                <Checkbox label="吃饭"></Checkbox>
		                <Checkbox label="睡觉"></Checkbox>
		                <Checkbox label="跑步"></Checkbox>
		                <Checkbox label="看电影"></Checkbox>
		            </CheckboxGroup>
		        </FormItem>
		        <FormItem label="借贷描述" prop="desc">
		            <Input v-model="formValidate.desc" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="输入借贷原因"></Input>
		        </FormItem>
		        <FormItem>
		            <Button type="primary" @click="handleSubmit('formValidate')">提交</Button>
		            <Button type="ghost" @click="handleReset('formValidate')" style="margin-left: 8px">重置</Button>
        		</FormItem>
    		</Form>
			
		</div>	
		
</template>

<script>
	export default ({
		name:'applyNow',
		data(){
			return {
				productName:'',
				//表单部分
				formValidate: {
                    name: '',
                    idNum:'',
                    phoneNum:'',
                    mail: '',
                    city: '',
                    gender: '',
                    interest: [],
                    date: '',
                    //time: '',
                    desc: ''
                },
                ruleValidate: {
                    name: [
                        { required: true, message: '姓名不能为空', trigger: 'blur' }
                    ],
                    idNum: [
                        { required: true,message:'身份证号不能为空', trigger: 'blur' },
                        { type: 'string',pattern:/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, message: '身份证格式不正确', trigger: 'blur' }
                    ],
                    phoneNum: [
                        { required: true,message:'手机号不能为空', trigger: 'blur' },
                        { type: 'string',pattern:/^1[3|4|5|8][0-9]\d{4,8}$/, message: '手机号格式不正确', trigger: 'blur' }
                    ],
                    mail: [
                        { required: true, message: '邮箱不能为空', trigger: 'blur' },
                        { type: 'email', message: '邮箱格式不正确', trigger: 'blur' }
                    ],
                    city: [
                        { required: true, message: '请选择居住地址', trigger: 'change' }
                    ],
                    gender: [
                        { required: true, message: '请选择性别', trigger: 'change' }
                    ],
                    interest: [
                        { required: true, type: 'array', min: 1, message: '请选择您的爱好', trigger: 'change' },
                        { type: 'array', max: 2, message: '最多选择2项', trigger: 'change' }
                    ],
                    date: [
                        { required: true, type: 'date', message: '请选择出生日期', trigger: 'change' }
                    ],
                    time: [
                        { required: true, type: 'date', message: 'Please select time', trigger: 'change' }
                    ],
                    desc: [
                        { required: true, message: '请描述您的借贷原因', trigger: 'blur' },
                        { type: 'string', min: 20, message: '描述不得少于20个字', trigger: 'blur' }
                    ]
                }
			}
		},
		methods : {
			getPidDetail(){
				var that = this
				this.$ajax({
					url:'/api/home/detail',
					method:'post',
					data:{
						id:that.$route.query.pId
					}
				})
				.then(function(res){
					if (res.data.code ==200  ) {
						that.productName = res.data.data.title
					}
				})
			},
			//提交
			 handleSubmit (name) {
			 	var that = this
                this.$refs[name].validate((valid) => {
                    if (valid) {
                    	//验证通过后写ajax提交
                    	this.$Message.success('Success!');
                    } else {
                        this.$Message.error('Fail!');
                    }
                })
            },
            //重置
            handleReset (name) {
                this.$refs[name].resetFields();
            }
		},
		mounted(){
			this.getPidDetail();
		}
	})
		
</script>

<style scoped lang="less">
	.apply_box{
		width:500px;
		height: 100%;
		margin:20px auto;
		h3{
			height:50px;line-height:50px;text-align: center;
			span{
				color: red;
			}
		}
	}


</style>